__author__ = 'Brandon Corfman'
import unittest
from game import Game
from humanagent import HumanAgent
from dwarves import GoldDigger
from path import Path, Goal

class TestSinglePathUnconnected(unittest.TestCase):
    """
    A North-South-East-West path card laid down, unconnected to any other card.
    Should fail.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.path = Path('NSEW', 'NSEW')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(5, 5, self.path, self.game.board),
                         False)

        
class TestPathMatch3Sides(unittest.TestCase):
    """
    A North-East-West path card validated against a proper 3-sided match within an existing path.
    Should succeed.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.game.board.path[4][2] = Path('NEW', 'NEW')
        self.game.board.path[3][2] = Path('SE', 'SE')
        self.game.board.path[3][3] = Path('SEW', 'SEW')
        self.game.board.path[3][4] = Path('SW', 'SW')
        self.game.board.path[4][4] = Path('NW', 'NW')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(4, 3, Path('NEW','NEW'), self.game.board),
                         True)

class TestPathNoMatch2Side(unittest.TestCase):
    """
    A North-East-West path card validated against a proper 2-sided match within an existing path.
    Should fail.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.game.board.path[4][2] = Path('NEW', 'NEW')
        self.game.board.path[3][2] = Path('SE', 'SE')
        self.game.board.path[3][3] = Path('EW', 'EW')
        self.game.board.path[3][4] = Path('SW', 'SW')
        self.game.board.path[4][4] = Path('NW', 'NW')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(4, 3, Path('NEW','NEW'), self.game.board),
                         False)

class TestPathMatch2Sides(unittest.TestCase):
    """
    A North-West path card validated against a proper 2-sided match within an existing path.
    Should succeed.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.game.board.path[4][2] = Path('NEW', 'NEW')
        self.game.board.path[3][2] = Path('SE', 'SE')
        self.game.board.path[3][3] = Path('SEW', 'SEW')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(4, 3, Path('NW','NW'), self.game.board),
                         True)

class TestPathMatch1Side(unittest.TestCase):
    """
    A East-West path card validated against a proper 1-sided match within an existing path.
    Should succeed.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.game.board.path[4][2] = Path('NEW', 'NEW')
        self.game.board.path[3][2] = Path('SE', 'SE')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(4, 3, Path('EW','EW'), self.game.board),
                         True)

class TestPathNoMatch1Side(unittest.TestCase):
    """
    A North-West path card validated against a proper 1-sided match within an existing path.
    Should fail.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.game.board.path[4][2] = Path('NEW', 'NEW')
        self.game.board.path[3][2] = Path('SE', 'SE')
        self.game.board.path[3][3] = Path('EW', 'EW')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(4, 3, Path('NW','NW'), self.game.board),
                         False)


class TestPathToGoalMatch(unittest.TestCase):
    """
    An east-west path leading straight to the goal.  Should succeed in validating and revealing the gold.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.dwarf_list = [GoldDigger, GoldDigger, GoldDigger, GoldDigger]
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.game.board.path[4][8] = Goal('NSEW', 'gold')
        self.game.board.path[4][2] = Path('EW', 'EW')
        self.game.board.path[4][3] = Path('EW', 'EW')
        self.game.board.path[4][4] = Path('EW', 'EW')
        self.game.board.path[4][5] = Path('EW', 'EW')
        self.game.board.path[4][6] = Path('EW', 'EW')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(4, 7, Path('EW','EW'), self.game.board),
                         True)

    def testReveal(self):
        self.game.board.set_path(self.game.players[0], 4, 7, Path('EW','EW'))
        self.assertEqual(self.game.board.path[4][8].reveal, True)

class TestPathToGoalNoMatch(unittest.TestCase):
    """
    An east-west path that heads north just before the goal.  Should succeed in validating
    but not in revealing the gold.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.game.board.path[4][8] = Goal('NSEW', 'gold')
        self.game.board.path[4][2] = Path('EW', 'EW')
        self.game.board.path[4][3] = Path('EW', 'EW')
        self.game.board.path[4][4] = Path('EW', 'EW')
        self.game.board.path[4][5] = Path('EW', 'EW')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(4, 7, Path('NW','NW'), self.game.board),
                         False)

    def testReveal(self):
        self.game.board.set_path(self.game.players[0], 4, 7, Path('NW','NW'))
        self.assertEqual(self.game.board.path[4][8].reveal, False)

class TestUnconnectedPathToGoalMatch(unittest.TestCase):
    """
    An unconnected north-west path next to the goal.  Should fail.
    """
    def setUp(self):
        self.game = Game()
        self.game.num_players = 3
        self.game.add_player(HumanAgent, GoldDigger, 'Test')
        self.game.board.path[4][8] = Goal('NSEW', 'gold')

    def testValidate(self):
        self.assertEqual(self.game.players[0].validate(4, 7, Path('EW','EW'), self.game.board),
                         False)

    def testReveal(self):
        self.game.board.set_path(self.game.players[0], 4, 7, Path('NW','NW'))
        self.assertEqual(self.game.board.path[4][8].reveal, False)
            
if __name__ == '__main__':
    unittest.main()
